package org.example;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class API_Demo5 {
    public static void main(String[] args) throws ParseException {
        /*System.out.println(toBinary(10));
        System.out.println(Integer.toBinaryString(10));
        System.out.println("=========1");
        //JDK7形式  计算已经活了多少天
        System.out.println("请输入你的出生日期:");
        Scanner s = new Scanner(System.in);
        String birthday = s.nextLine();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date date=sdf.parse(birthday);
        long birthtime=date.getTime();
        long nowtime=System.currentTimeMillis();
        long day=(nowtime-birthtime)/1000/60/60/24;
        System.out.println("你已经活了"+day+"天");
        //JDK8形式
        System.out.println("=========2");
        System.out.println("请输入你的出生日期:");
        Scanner s1 = new Scanner(System.in);
        String birthday1 = s1.nextLine();
        //parse是静态方法
        LocalDate ld1=LocalDate.parse(birthday1);
        LocalDate ld2=LocalDate.now();
        long day1=ChronoUnit.DAYS.between(ld1,ld2);
        System.out.println("你已经活了"+day1+"天");*/
        //判断是否为闰年
        //jdk7
        Calendar c = Calendar.getInstance();
        c.set(2024,2,1);//月份范围是0-11
        c.add(Calendar.DAY_OF_MONTH,-1);
        int day1=c.get(Calendar.DAY_OF_MONTH);
        System.out.println(day1);
        //jdk8
        LocalDate ld3 = LocalDate.of(2004,3,1);
        LocalDate ld4=ld3.minusDays(1);
        System.out.println(ld4);
        //true 闰 false平
        System.out.println(ld3.isLeapYear());

    }
    public static String toBinary(int number){
        StringBuilder sb = new StringBuilder();
        while(true){
            if(number==0){
                break;
            }
            int num=number%2;
            //insert
            sb.insert(0,num);
            number/=2;
        }
        return sb.toString();
    }
}
